package com.spj.controller;

import com.spj.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author :spj
 * @Date:2022/3/30
 * @description:
 */
@RequestMapping("/demo")
@Controller
public class DemoController {
    @RequestMapping("/demo1")
    public ModelAndView demo1(String name,int age){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("name",name);
        modelAndView.addObject("age",age);
        modelAndView.setViewName("/WEB-INF/jsp/success.jsp");
        return modelAndView;
    }
    @RequestMapping("/demo2")
    public ModelAndView demo2(User user){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("name",user.getName());
        modelAndView.addObject("age",user);
        modelAndView.setViewName("/WEB-INF/jsp/success.jsp");
        return modelAndView;
    }
    @RequestMapping(value = "/demo3")
    public ModelAndView demo3(@RequestParam Map<String,Object> info, @RequestParam List<String> hobby){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("name",info);
        modelAndView.addObject("age",hobby);
        modelAndView.setViewName("/WEB-INF/jsp/success.jsp");
        return modelAndView;
    }
    @RequestMapping(value = "/demo4")
    public ModelAndView demo4(Date date){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("name","Date");
        modelAndView.addObject("age",date);
        modelAndView.setViewName("/WEB-INF/jsp/success.jsp");
        return modelAndView;
    }

}
